*---- Authors: Maria Nordbrandt, Gina Gustavsson, Karen Nielsen Breidahl
*---- The Unifying Magic, EJPR 2025

set more off

*TREATMENT GROUPS

*Pure flag treatment
gen treat_flag=.
	replace treat_flag=1 if Splitgroup==1
	replace treat_flag=0 if  Splitgroup==2
	
	label variable treat_flag "Flag treat."

label variable treat_flag "Flag treat. 1"
	label define treat_flag 0 "  Control", modify
	label define treat_flag 1 "  Treat. 1", modify
	label value treat_flag treat_flag

*Cake treatment
gen treat_cake=.
	replace treat_cake=1 if Splitgroup==3
	replace treat_cake=0 if  Splitgroup==4 

label variable treat_cake "Cake treat. 2"
	label define treat_cake 0 "  Control", modify
	label define treat_cake 1 "  Treat. 2", modify
	label value treat_cake treat_cake


*BOTH FLAG TEATMENTS COMBINED
	gen treat_bothflags=.
	replace treat_bothflags=1 if Splitgroup==1  |Splitgroup==3
	replace treat_bothflags=0 if  Splitgroup==2 | Splitgroup==4 


********************************************************
	
*COMTROLS
	


*Gender (gender)
tab gender
gen woman=gender-1


*Age (age)
*tab age
gen age_n=(age-18)/(98-18)
gen age_d=age
recode age_d (18/30=1) (31/40=2) (41/50=3) (51/60=4) (61/70=5) (71/98=6)
tab age_d
*drop age_d

*Education (short medium long)
tab profile_education
gen educat=profile_education
gen educat_n=(educat-1)/(8-1)
gen educ_d=educat
recode educ_d (1/4=1) (5/8=2)


*HH income

tab household_income
gen HH_income=household_income

*keep 12 and 13 because almost 700 people or colse to 20% of the sample did not want to state their income.
*Dropping them would result in a significant power loss.
*Generate a categorical dummy to handle this.
gen HH_inc_d6=.
replace HH_inc_d6=1 if(household_income==1  | household_income==2)
replace HH_inc_d6=2 if(household_income==3  | household_income==4)
replace HH_inc_d6=3 if(household_income==5  | household_income==6)
replace HH_inc_d6=4 if(household_income==7  | household_income==8)
replace HH_inc_d6=5 if(household_income==9  | household_income==10 | household_income==11)
replace HH_inc_d6=6 if(household_income==12  | household_income==13)
tab HH_inc_d6	
*drop HH_inc_d6

*Dichotomous HH_income variable for subgroup analyses
gen HH_inc_d=household_income
recode HH_inc_d (1/5=0) (6/11=1) (12 13=.)



*Left-right
tab Q3_1
gen ideology=Q3_1
gen ideology_n=(ideology-0)/(10-0)

*Left-right dummy
gen right=ideology
recode right(0/4=1) (5=2) (6/10=3) 

label variable right "Left-Middle-Right dummy"
		 label define right 1 "     Left", modify
		 label define right 2 "     Middle", modify 
		 label define right 3 "     Right", modify
		 label value right right
		 

*Personality

*Q1_1 Q1_2 Q1_3 Q1_4 Q1_5 Q1_6 Q1_7 Q1_8 Q1_9 Q1_10

*Extroverted=Q1_1 Q1_5R
*Agreeable=Q1_2R Q1_7 
*Conscientiousness=Q1_3 Q1_8R
*Neuroticism=Q1_4 Q1_9R
*Openness=Q1_5 Q1_10R
tab Q1_6
gen extro_r=8-Q1_6
gen extro=Q1_1+extro_r
gen extro_n=(extro-2)/(14-2)

gen extro_d=extro_n
recode extro_d (0/0.5=0) (0.51/1=1)

gen agree_r=8-Q1_2
gen agree=Q1_7+agree_r
gen agree_n=(agree-2)/(14-2)

gen agree_d=agree_n
recode agree_d (0/0.5=0) (0.51/1=1)

gen conscien_r=8-Q1_8
gen conscien=Q1_3+agree_r
gen conscien_n=(conscien-3)/(14-3)

gen conscien_d=conscien_n
recode conscien_d (0/0.5=0) (0.51/1=1)

gen neuro_r=8-Q1_9
gen neuro=Q1_4+neuro_r
gen neuro_n=(neuro-2)/(14-2)

gen neuro_d=neuro_n
recode neuro_d (0/0.5=0) (0.51/1=1)

gen open_r=8-Q1_10
gen open=Q1_5+open_r
gen open_n=(open-2)/(14-2)

gen open_d=open_n
recode open_d (0/0.5=0) (0.51/1=1)



********************************************************
	
*MEDIATORS


*Code the NATIONAL ATTACHMENT variable

		gen attach=Q7
		gen attach_r=5-attach
		gen attach_n=(attach_r-0)/(4-0)
		*higher values more attachment

*Code NATIONAL IDENTIFICATION variable
*remove 6, I am not Swedish/Danish
		gen ident=Q8
		recode ident (6=.)
		gen ident_r=5-ident
		gen ident_n=(ident_r-0)/(4-0)
		*higher values more identification


*GENERATE COMBINED IDENTIFICATION/ATTACHMENT VARIABLE
alpha attach_n ident_n
*0.79 in Denmark, 0,74 in Sweden, 0.76 in full sample

egen identity_n=rowmean(attach_n ident_n)

*NATIONAL PRIDE
*remove 6, I am not Swedish/Danish
		gen proud=Q9
		recode proud (6=.)
		gen proud_r=5-proud
		gen proud_n=(proud_r-0)/(4-0)
		*higher values more pride

	*Institutional pride and cultural pride
		foreach x of varlist Q10_1-Q10_10 {
		local i = `i' + 1
		gen pride`i' = `x'
		}
		
		foreach x of varlist pride1-pride10 {
		gen `x'_r=5-`x'
		}
		
		foreach x of varlist pride1_r-pride10_r {
		gen `x'_n=(`x'-0) / (4-0)
		}
		
		alpha pride1_r_n-pride10_r_n, item
		*0.84 in full sample
		
		egen pride_n=rowmean(pride1_r_n-pride10_r_n)
		
		factor pride1_r_n-pride10_r_n
		rotate
		
		egen pride_inst_n=rowmean(pride1_r_n-pride4_r_n pride10_r_n)
		egen pride_cult_n=rowmean(pride5_r_n-pride7_r_n pride9_r_n)
		tab pride_inst_n
		tab pride_cult_n


